/**
 * Copyright (c) 2014-2018, huli.com
 * All rights reserved.
 */
package com.xiaohujr.xuexue.javaguide;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

/**
 * 进程线程.
 * 一个进程里的线程，共享堆和方法区及运行时常量池（方法区包含了运行时常量池）
 * 线程内存区域（运行时数据区域）包括了虚拟机栈，本地方法栈，程序计数器
 *
 * @author Xue Xue (xuexue1@huli.com)
 * @version $Id$
 * @since 2020/1/18
 */
public class ThreadBasic {
    public static void main(String[] args) {
        // 获取 Java 线程管理 MXBean
        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(false, false);
        // 遍历线程信息，仅打印线程 ID 和线程名称信息
        for (ThreadInfo threadInfo : threadInfos) {
            System.out.println("[" + threadInfo.getThreadId() + "] " + threadInfo.getThreadName());
        }
        ThreadLocal threadLocal = new ThreadLocal();
    }
}
